package com.zky.gulimall.order.config;

import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

/**
 * @Description TODO
 * @Author 张开源
 * @Date 2022/12/19 16:32
 * @Version 1.0
 **/
public class Test {
    public static void main(String[] args) {

        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        System.out.println("排序前:"+list);
        int size = list.size();
        List<Integer> newList = new ArrayList<>();
        for (int i = 0; i < size; i++) {
            Integer max = getMax(list);
            System.out.println("max:"+max);
            list.remove(max);

            newList.add(max);

        }
        System.out.println("排序后:"+newList);

    }

    private static Integer getMax(List<Integer> list) {
        if (CollectionUtils.isEmpty(list)) {
            return null;
        }
        Integer max = list.get(0);
        for (int i = 0; i < list.size(); i++) {
            if(list.get(i)>max){
                max=list.get(i);
            }
        }
        return max;
    }


}
